package LogUtil;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Logger {
    /*
    记录日志的方法
     */
    public static void log(String msg) {
        try {
            //指向一个日志文件
            PrintStream out = new PrintStream(new FileOutputStream("chapter21//src//LogUtil//log.txt",true));
            //改变输出流方向
            System.setOut(out);
            //当前时间
            Date nowTime = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String strTime =sdf.format(nowTime);

            System.out.println(strTime + ":" + msg);


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }


}
